package com.ctshk.sapp.goods.controller;


import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.SystemError;
import com.ctshk.common.exception.BusinessException;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.goods.req.CommoditySpecificationsAttributeAddReq;
import com.ctshk.rpc.goods.service.ICommoditySpecificationsAttributeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * <p>
 * 商品规格属性表 前端控制器
 * </p>
 *
 * @author 姜斌文
 * @since 2021-04-12
 */
@RestController
@Api(value = "商品规格属性", tags = "商品规格属性")
@RequestMapping("/commodity/specificationsAttribute")
public class CommoditySpecificationsAttributeController extends BaseController {

    @DubboReference
    ICommoditySpecificationsAttributeService commoditySpecificationsAttributeService;

    @ApiOperation(value = "新增商品规格属性", notes = "新增商品规格属性")
    @PostMapping("/insertCommoditySpecificationsAttribute")
    public Result insertCommoditySpecificationsAttribute(@RequestBody @Valid CommoditySpecificationsAttributeAddReq obj) throws Exception {
        CommoditySpecificationsAttributeAddReq commoditySpecificationsAttributeAddReq = commoditySpecificationsAttributeService.insertCommoditySpecificationsAttribute(obj, getCurrentUser(getRequest()));
        if(commoditySpecificationsAttributeAddReq == null){
            return Result.failed(new BusinessException(SystemError.GOODS_ATTRIBUTE_ERROR_40017));
        }
        return Result.success(commoditySpecificationsAttributeAddReq);
    }
}
